package com.tlx.util;

import java.util.HashMap;
import java.util.Map;

public class PNumberUtils {

    private static final Map<String, String> chineseMap = new HashMap<String, String>();

    static {
        chineseMap.put("一", "1");
        chineseMap.put("元", "1");
        chineseMap.put("二", "2");
        chineseMap.put("三", "3");
        chineseMap.put("四", "4");
        chineseMap.put("五", "5");
        chineseMap.put("六", "6");
        chineseMap.put("七", "7");
        chineseMap.put("八", "8");
        chineseMap.put("九", "9");
        chineseMap.put("〇", "0");
        chineseMap.put("零", "0");
        chineseMap.put("十", "10");
        chineseMap.put("百", "100");
    }

    public static void main(String[] args) {
        int i = judgeChineseData("十五");
        System.out.println(i);
    }

    public static int judgeChineseData(String value) {
        int sumNum = 0;
        int unitValue = 0;
        for (int i = 0; i < value.length(); i++) {
            char te = value.charAt(i);
            int temp = Integer.parseInt(chineseMap.get(String.valueOf(te)));
            switch (temp) {
            case 100:
                if (unitValue == 0) {
                    unitValue = 1;
                }
                sumNum += unitValue * temp;
                unitValue = 0;
                break;
            case 10:
                if (unitValue == 0) {
                    unitValue = 1;
                }
                sumNum += unitValue * temp;
                unitValue = 0;
                break;
            default:
                unitValue += temp;
                break;
            }
        }
        sumNum += unitValue;
        return sumNum;
    }

}
